﻿using ZquenceStudio3Host.DspPlugins.Synthesizers.Nodesizer.Engine;

namespace DefaultDspPlugins.Common.Modulizer.Engine.Modules.LowLevel
{
    [ModuleDisplay("Delay")]
    class DelayModule : BaseModule
    {
        public readonly ModuleInput In;
        public readonly ModuleOutput Out;
        public InputModuleParameter Delay { get; private set; }

        public DelayModule(ModuleManager manager)
            : base(manager)
        {
            // Add input and outputs to module.
            AddInput(In = new ModuleInput("In", IOType.Audio, this));
            AddOutput(Out = new ModuleOutput("Out", IOType.Audio, this));

            Delay = new InputModuleParameter(this, "Delay", 100, IOType.Audio);
            Delay.Label = "Delay ms";
            Delay.MinValue = 1;
            Delay.MaxValue = 44100;
            AddModuleParameter(Delay);
        }

        public override void Process()
        {
            // First check if both inputs sources is connected.
            if (In.IsConnected)
            {
                for (int i = 0; i < Out.AudioBuffer.Length; i++)
                {
                    Out.AudioBuffer[i] = In.FromOutput.AudioBuffer[i];
                }
            }
        }
    }
}
